package com.example.hospital.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.hospital.dto.PaymentQuery;
import com.example.hospital.entity.Payment;
import com.example.hospital.service.PaymentService;
import com.example.hospital.mapper.PaymentMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Oreki
 * @description 针对表【payment】的数据库操作Service实现
 * @createDate 2024-12-27 16:53:20
 */
@Service
public class PaymentServiceImpl extends ServiceImpl<PaymentMapper, Payment>
        implements PaymentService {

    @Override
    public List<Payment> listPayments(PaymentQuery paymentQuery) {
        if (paymentQuery == null) {
            return list();
        }
        Integer patientId = paymentQuery.getPatientId();
        String startTime = paymentQuery.getStartTime();
        String endTime = paymentQuery.getEndTime();
        String paymentMethod = paymentQuery.getPaymentMethod();
        String status = paymentQuery.getStatus();
        return lambdaQuery()
                .eq(patientId != null, Payment::getPatientId, patientId)
                .ge(StrUtil.isNotEmpty(startTime), Payment::getPaymentTime, startTime)
                .le(StrUtil.isNotEmpty(endTime), Payment::getPaymentTime, endTime)
                .eq(StrUtil.isNotEmpty(paymentMethod), Payment::getPaymentMethod, paymentMethod)
                .eq(StrUtil.isNotEmpty(status), Payment::getStatus, status)
                .list();
    }
}




